/* 矩阵相关操作:
将正方形矩阵顺时针转动90度
之字形打印矩阵
在行列都排好序（升序）的矩阵中找数
 */
 
//将正方形矩阵顺时针转动90度
public void rotate(int[][] matrix){
	int tR=0;
	int tC=0;
	int dR=matrix.length-1;
	int dC=matrix[0].length-1;
	while(tR<dR){
		rotateEdge(matrix,tR++,tC++,dR--,dC--);
	}
}
public void rotateEdge(int[][] m,int tR,int tC,int dR,int dC){
	int times = dC-tC;
	int temp = 0;
	for(int i=0;i!=times;i++){
		temp = m[tR][tC+i];
		m[tR][tC+i] = m[dR-i][tC];
		m[dR-i][tC] = m[dR][dC-i];
		m[dR][dC-i] = m[tR+i][dC];
		m[tR+i][dC] = temp;
	}
}

//之字形打印矩阵
public void printMatrixZigZag(int[][] matrix){
	int tR=0;
	int tC=0;
	int dR=0;
	int dC=0;
	int endR=matrix.length-1;
	int endC=matrix[0].length-1;
	boolean fromUp = false;
	while(tR<endR+1){
		printLevel(matrix,tR,tC,dR,dC,fromUp);
		tR = tC==endC?tR+1:tR;
		tC = tC==endC?tC:tC+1;
		dC = dR==endR?dC+1:dC;
		dR = dR==endR?dR:dR+1;
		fromUp =!fromUp;
	}
}
public void printLevel(int[][] m,int tR,int tC,int dR,int dC,boolean f){
	if(f){
		while(tR!=dR+1){
			System.out.print(m[tR++][tC--]+"");
		}
	}else{
		while(dR!=tR-1){
			System.out.print(m[dR--][dC++]+"");
		}
	}
}

//在行列都排好序（升序）的矩阵中找数
public boolean isContains(int[][] matrix,int K){
	int row = 0;
	int col = matrix[0].length-1;
	while(row<matrix.length&&col>=0){
		if(matrix[row][col]>K){
			return true;
		}els if(matrix[row][col]>K){
			col--;
		}else{
			row++;
		}
	}
}
 
 
 




 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 